//
//  WZixunViewCell.swift
//  iiatn
//
//  Created by mine on 18/3/29.
//  Copyright © 2018年 mnine. All rights reserved.
//

import UIKit
import Kingfisher
import SVProgressHUD

class WZixunViewCell: UITableViewCell {

    
    @IBOutlet var zxltitle: UILabel!
    
    @IBOutlet var zxlimage: UIImageView!
    
    @IBOutlet var zxlclicknum: UILabel!
    
    @IBOutlet var zxltime: UILabel!
    
    @IBOutlet var zxSc: UIButton!
    
    
    var zixunItem: WZiXun? {
        didSet {
            let url = zixunItem!.thumb
            if (url!.isEmpty){
                zxlimage.image = UIImage(named:"default_bg")
            }else{
                zxlimage.kf.setImage(with: URL(string: url!)!, placeholder: UIImage(named: "default_bg"), options: nil, progressBlock: nil)
            }
            zxltitle.width = SCREENW - 170
            zxltitle.text = zixunItem!.title
            zxlclicknum.text = "阅读量：\(zixunItem!.click_num!)"
            zxltime.text = zixunItem!.created_at
        }
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        zxlimage.layer.cornerRadius = kCornerRadius
        zxlimage.layer.masksToBounds = true
        zxlimage.layer.shouldRasterize = true
        zxlimage.layer.rasterizationScale = UIScreen.main.scale
        zxlimage.x = SCREENW - zxlimage.width - 20
        zxltime.x = zxlimage.x
        
        zxSc.addTarget(self, action: #selector(sc), for: .touchUpInside)
    }

    func sc(){
        if whaslogin!{
            WNetwork.shareNetworkTool.shoucangZX(user_id: wuserid!, zxc_id: zixunItem!.id!)
        }else{
            toLogin()
        }
    }
    func toLogin(){
//        let loginVC = WLoginViewController()
//        loginVC.title = "登录"
//        let nav = WNavigationController(rootViewController: loginVC)
//        present(nav, animated: true, completion: nil)
        SVProgressHUD.showInfo(withStatus: "暂未登录！")
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
